home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / gate / Gate_SetFile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  1.6 KB  |  60 lines

  1. /* 
  2.  * Gate_SetFile.c --
  3.  *
  4.  *    Source code for the Gate_SetFile library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/gate/RCS/Gate_SetFile.c,v 1.1 92/06/04 22:03:22 jhh Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <stdio.h>
  21. #include <gate.h>
  22. #include <gateInt.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26. /*
  27.  *-----------------------------------------------------------------------
  28.  *
  29.  * Gate_SetFile --
  30.  *
  31.  *    Change the file being used to fetch info.
  32.  *
  33.  * Results:
  34.  *    Zero is returned if all went well.  If an error occurred,
  35.  *    then -1 is returned and errno tells exactly what went wrong.
  36.  *
  37.  * Side Effects:
  38.  *    The old file is closed. A Gate_Start need not be given as the
  39.  *    file will be open already.
  40.  *
  41.  *-----------------------------------------------------------------------
  42.  */
  43.  
  44. int
  45. Gate_SetFile(fileName)
  46.     char          *fileName;    /* File to use as the database */
  47. {
  48.     if (gateFile != (FILE *) NULL) {
  49.     fclose(gateFile);
  50.     }
  51.     gateFile = fopen(fileName, "r");
  52.     if (gateFile == (FILE *) NULL) {
  53.     return -1;
  54.     } else {
  55.     gateFileName = malloc((unsigned) (strlen(fileName) + 1));
  56.     strcpy(gateFileName, fileName);
  57.     }
  58.     return 0;
  59. }
  60.